<template>
  <div class="view-wrapper">
    <div class="listBox">
      <div class="title">短信发送控制</div>
      <div class="list">短信可发送总条数：{{configData.total}}条</div>
      <div class="list">已发送短信总条数：{{configData.used}}条</div>
      <div class="list">当前可用短信数量：{{configData.usable}}条</div>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm"  class="demo-ruleForm">
        <el-form-item label="增加可用条数：" prop="increment">
          <el-input type="text" v-model="ruleForm.increment" autocomplete="off" placeholder="请输入数量"></el-input>
          <el-button type="primary" @click="submitForm('ruleForm')" class="mar-l" :loading="loading">确认添加</el-button>
        </el-form-item>
      </el-form>
      </div>
  </div>
</template>
<script>
  // components
  import {
    getMessageConfig,
    setMessageConfig
  } from "@/api/smsConfiguration";
  
  
  export default {
    name: "billList",
    components: {
      
    },
    data() {
      return {
        loading: false,
      
        id: '',
        path: '',
        configData: {},
        ruleForm: {
          id: '',
          increment: "", 
        },
        rules: {
          increment: [
            { required: true,message: '请输入数量',trigger: 'blur' }
          ],
        },
      
        
      };
    },
    computed: {
      
    },
    created() {
      this.gitInfo()
    },
    methods: {
      gitInfo(){
        getMessageConfig().then(res => {
          this.configData = res.result
          this.ruleForm.id = res.result.id
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.loading = true
              var data = {
              ...this.ruleForm
              }
              setMessageConfig(data).then(res => {
                this.handleSuccess("设置成功")
                this.gitInfo()
                this.loading = false
              }).finally(() => {
                this.loading = false
              })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      handleSuccess(msg) {
        if (msg === '已拒绝') {
          var type = 'error'
        } else {
          var type = 'success'
        }
        this.$message({
          message: msg,
          type: type,
          duration: 1500,
          onClose: () => {
            this.handleClose()
            this.$emit('success')
          }
        })
      },
    },
  };

</script>
<style lang="scss" scoped>
  .listBox {
    //   box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }
  .title{
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 20px;
  }
  .list{
    height: 70px;
    display: flex;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
  }
  .el-input{
    width: 200px;
  }
  .mar-l{
    margin-left: 10px;
  }
  ::v-deep .el-form-item__label{
    font-size: 20px;
    font-weight: bold;
    color: #000;
  }
</style>
